import os

from pydub import AudioSegment

base_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# 设置ffmpeg路径，如果ffmpeg已添加到系统路径可以省略
# AudioSegment.ffmpeg = r"C:\path\to\ffmpeg.exe"  # 如果没有设置环境变量，取消注释并设置路径
# 读取m4a文件

# 手动指定 FFmpeg 路径
# AudioSegment.ffmpeg = "E:\soft\\ffmpeg-2024-10-02-git-358fdf3083-full_build\\bin\\ffmpeg.exe"

target_file_path = f"{base_path}/mydada/input/yzhs.m4a"
if os.path.exists(target_file_path):
    print("文件存在")

audio = AudioSegment.from_file(target_file_path, format="m4a")

# 保存为wav格式
audio.export(f"{base_path}/mydada/input/yzhs2.wav", format="wav")

print("转换完成！")

# ffmpeg.exe -i "D:\code\play\SenseVoice-main\mydada\input\yzhs.m4a" "D:\code\play\SenseVoice-main\mydada\input\yzhs.wav"